<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/8/24 01:42
 */

namespace module\user\controller;

use module\user\library\UserController;
use module\user\logic\SignInLogic;
use mof\annotation\Inject;
use mof\ApiResponse;
use think\db\exception\DbException;
use think\response\Json;

/**
 * 积分任务
 */
class SignIn extends UserController
{

    /**
     * @var SignInLogic
     */
    #[Inject]
    protected SignInLogic $logic;

    /**
     * 签到
     * @return Json
     */
    public function tick(): Json
    {
        $params = [
            'user_id' => $this->auth->getId(),
            'day'     => date('Y-m-d'),
        ];
        return ApiResponse::success($this->logic->tick($params));
    }

    /**
     * 签到日历
     */
    public function month(): Json
    {
        $params = $this->request->withValidate([
            'year|年份'  => 'integer|between:2023,2030',
            'month|月份' => 'integer|between:1,12'
        ])->get();

        return ApiResponse::success(
            $this->logic->getByMonth(
                $this->auth->getId(), $params['year'], $params['month']
            )
        );
    }

    /**
     * 最后一条数据
     * @return Json
     */
    public function last(): Json
    {
        return ApiResponse::success($this->logic->getLastData($this->auth->getId()));
    }

}